DBtools.h++ Sample Code

This page provides sample code that shows how easy it is to use DBtools.h++ to pull sales data from the corporate database into a spreadsheet. The syntax is straightforward C++ and the database operations use names familiar to database developers.

From this page, you can also access:

Program

#include <rw/db/db.h>

int main ()
{
   1	RWDBDatabase enterpriseDB = RWDBManager::database
	   ("SYBASE", "SYBASESERVER", "ME", "PASSWORD", "DATA");

	RWDBTable table1 = enterpriseDB.table("Actual_Sales");

	RWDBReader table1Reader = table1.reader();

   2	RWDBDatabase spreadsheet = RWDBManager::database
	   ("ODBC", "MS_EXCEL", "ME", "PASSWORD", "C:\\mydir");

   3	spreadsheet.createTable ("TMPSALES", table1.schema());
	RWDBTable spreadsheetTable = spreadsheet.table ("TMPSALES");

   4	RWDBInserter localInserter = spreadsheetTable.inserter();
	while (tableReader());
	{
	   localInserter << table1Reader;
	   localInserter.execute();
	}
	...
   5	/* 	Insert DDE code to plot your sales forecast, stored
		in the second spreadsheet, versus actual sales now
		stored in the TMPSALES spreadsheet. */

Explanation

  1. Connect to the enterprise database, which contains recorded sales for the year.
  2. Connect to the second database; in this case a spreadsheet with an ODBC driver.
  3. Use DBtools.h++ to build and execute a SQL statement that creates a table. Via ODBC, this creates a spreadsheet named TMPSALES to temporarily store the sales records.
  4. Insert the sales records into the spreadsheet, with DBtools.h++ automatically mapping the datatypes from Database 1 to types known to Database 2. The data fills the new spreadsheet starting at cell A1. (Take a moment and think about how tedious this would be using the ODBC API together with the API associated with your RDBMS.)
  5. Now use standard spreadsheet directives to plot the data youÆve brought from the enterprise database versus your own data stored in another spreadsheet.

© Copyright 1995, Rogue Wave Software, Inc.